package edu.neepu;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.Test;

import java.io.IOException;
import java.net.*;

public class BookCount {
    ChapCount chap = new ChapCount();

    /**
     *  bookName：中文书名
     *  urlPath：每一章的地址片段
     */
    public void CountBooks() throws IOException {
        String url = "http://www.shicimingju.com/book/";
        Document document = Jsoup.connect(url).timeout(100000).get();
        Elements listCount = document.select(".bookmark-list h2");
        for (Element element : listCount) {
            Element aList = element.select("a").first();
            String str = aList.attr("href");
            String bookName = aList.text();//获取中文名称
            String urlPath = str.substring(str.lastIndexOf("/")+1,str.lastIndexOf("."));//获取所有书名称路径
            //一本一本书爬取
            chap.CountChap(bookName,urlPath);
        }
    }
}